var ProcessingAS = {

	onLoad: function () {

		var script	= $("script[src*=processing.as.js]:first");
		var src			= script.attr("src");
		var query	= src.substr(src.indexOf("?") + 1);
		var parameters = query.split("&");
		
		var p = {};
		for (var i = 0; i < parameters.length; i++) {
			var keyAndValue = parameters[i].split("=");
			var key		=	keyAndValue.shift();
			var value		=	keyAndValue.shift();
			p[key] = value;
		}
		ProcessingAS.p = p;
		ProcessingAS.element = document.getElementById(ProcessingAS.p.id);

		var thumbnails	= $("ul.processingThumbnails li a:first");
		$.get($(thumbnails).attr("href"), function(source) {
				var source = source.replace(/size\(.*?,.*?\);/, "size\(" + ProcessingAS.p.width +"," + ProcessingAS.p.height + "\);");

				var images = [];
				var regex = /loadImage\(\"(.*)\"\);/g;
				var matches = source.match(regex);
				if (matches) {
					for (var i = 0; i < matches.length; i++) {
						var name = matches[i].replace(/loadImage\(\"(.*)\"\);/g, "$1");
						var path = new RegExp(name);
						source = source.replace(path, PImages[name]);
						images.push([PImages[name], PImages[name]]);
					}
				}
				ProcessingAS.element.run(source,images);
		});
	},
	
	onStart: function (stage) {
	},
	
	onStop: function (stage) {
	},

	onResize: function (w, h) {
		ProcessingAS.element.width = w;
		ProcessingAS.element.height = h;
	}
};